<?php
include('../data/comm.inc.php');include('../data/myadminvar.php');
include('../func/func.php');
include('../func/adminfunc.php');
include('../global/page.class.php');
include('../include.php');
include('./checklogin.php');
switch ($_REQUEST['xtype']) {
    case "show":
	    include("../global/Iplocation_Class.php");
        $posi = array(
            "slib" => "即时注单",
            "baox" => "报表",
            "lib" => "未结明细",
            "bao" => "报表",
            "suser" => "帐户管理",
            "xxtz" => "投注明细",
            "now" => "注单明细",
            "make" => "投注区",
            "long" => "开奖记录",
            "credit" => "个人信用",
            "libset" => "注单设置",
            "record" => "操作记录",
            "changepass2" => "密码更改",
            "error" => "异常注单"
        );
        $time = time();
        $msql->query("delete from `$tb_online`  where  $time-savetime>60*" . $config['livetime']);
        if ($_SESSION['hide'] == 1) {
            $rs = $msql->arr("select count(id) from `$tb_online` where xtype=0", 0);
        } else {
            $rs = $msql->arr("select count(id) from `$tb_online` where xtype=0 and userid!=10000", 0);
        }
        $num[] = $rs[0][0];
        $rs    = $msql->arr("select count(id) from `$tb_online` where xtype=1", 0);
        $num[] = $rs[0][0];
        $rs    = $msql->arr("select count(id) from `$tb_online` where xtype=2", 0);
        $num[] = $rs[0][0];
        $tpl->assign("num", $num);
        $msql->query("select count(id) from `$tb_online` where  xtype='$xtype'");
        $msql->next_record();
        $rcount   = $msql->f(0);
        $psize    = $config['psize'];
        $pcount   = $rcount % $psize == 0 ? $rcount / $psize : (($rcount - $rcount % $psize) / $psize) + 1;
        $thispage = $_REQUEST['page'];
        $xtype    = $_REQUEST['type'];
        if (!in_array($xtype, array(
            0,
            1,
            2
        )) | $xtype == '')
            $xtype = 2;
        if (!is_numeric($thispage) | $thispage == '')
            $thispage = 1;
        if ($_SESSION['hides'] == 1) {
            $msql->query("select *,ip as ips from `$tb_online` where xtype='$xtype' order by xtype,savetime desc limit " . (($thispage - 1) * $psize) . ",$psize");
        } else {
            $msql->query("select *,ip as ips from `$tb_online` where xtype='$xtype' and userid!=10000 order by xtype,savetime desc limit " . (($thispage - 1) * $psize) . ",$psize");
        }
        $i     = 0;
        $ipstr = '';
        $on    = array();
        while ($msql->next_record()) {
            $on[$i]['id'] = $msql->f('id');
            if ($msql->f('xtype') == 0) {
                $on[$i]['usertype'] = "管理";
                $on[$i]['username'] = transadmin($msql->f('userid'), 'adminname');
                $on[$i]['name']     = "管理";
            } else {
                if ($wid != $msql->f('wid')) {
                    $fsql->query("select layer from `$tb_web` where wid='" . $msql->f('wid') . "'");
                    $fsql->next_record();
                    $layer = json_decode($fsql->f('layer'));
                }
                $on[$i]['usertype'] = $layer[$msql->f('layer') - 1];
                if ($xtype == 2) {
                    $fsql->query("select username,name,fudong,maxmoney,money,kmaxmoney,kmoney,fid1,fid2,fid3,fid4,fid5,fid6,fid7,fid8 from `$tb_user` where userid='" . $msql->f('userid') . "'");
                    $fsql->next_record();
                    $on[$i]['username'] = $fsql->f('username');
                    $on[$i]['name']     = $fsql->f('name');
                    $on[$i]['com']      = $fsql->f('fid1');
                    if ($fsql->f('fudong') == 1) {
                        $on[$i]['maxmoney'] = '[现金]' . $fsql->f('kmaxmoney');
                        $on[$i]['money']    = '[现金]' . $fsql->f('kmoney');
                    } else {
                        if ($config['fast']==0) {
                            $on[$i]['maxmoney'] = $fsql->f('maxmoney');
                            $on[$i]['money']    = $fsql->f('money');
                        } else {
                            $on[$i]['maxmoney'] = $fsql->f('kmaxmoney');
                            $on[$i]['money']    = $fsql->f('kmoney');
                        }
                    }
                    if ($fsql->f('fid') != 99999999) {
                        $on[$i]['up']     = transu($fsql->f('fid1'));
                        $on[$i]['uplist'] = $on[$i]['up'];
                        for ($j = 2; $j <= 8; $j++) {
                            if ($fsql->f('fid' . $j) != 0) {
                                $on[$i]['uplist'] .= "<bR />" . transu($fsql->f('fid' . $j));
                            }
                        }
                    }
                    if ($config['fast'] == 0) {
                        $fsql->query("select sum(je) from `$tb_lib` where userid='" . $msql->f('userid') . "' and gid in (select gid from `$tb_game` where ifopen=1 and fast='0') and z=9");
                    } else {
                        $fsql->query("select sum(je) from `$tb_lib` where userid='" . $msql->f('userid') . "' and gid in (select gid from `$tb_game` where ifopen=1 and fast='1') and z=9");
                    }
                    $fsql->next_record();
                    $on[$i]['z9'] = pr0($fsql->f(0));
                } else {
                    $fsql->query("select username,name,fid1,fid2,fid3,fid4,fid5,fid6,fid7,fid8,fid,ifson from `$tb_user` where userid='" . $msql->f('userid') . "'");
                    $fsql->next_record();
                    $on[$i]['username'] = $fsql->f('username');
                    $on[$i]['name']     = $fsql->f('name');
                    $on[$i]['com']      = $fsql->f('fid1');
                    if ($fsql->f('ifson') == 1) {
                        $fsql->query("select username,name,fid1,fid2,fid3,fid4,fid5,fid6,fid7,fid8,fid,ifson from `$tb_user` where userid='" . $fsql->f('fid') . "'");
                        $fsql->next_record();
                        $on[$i]['name'] = $fsql->f('name') . '-子';
                    }
                    if ($fsql->f('fid') != 99999999) {
                        $on[$i]['up']     = transu($fsql->f('fid1'));
                        $on[$i]['uplist'] = $on[$i]['up'];
                        for ($j = 2; $j <= 8; $j++) {
                            if ($fsql->f('fid' . $j) != 0) {
                                $on[$i]['uplist'] .= "<bR />" . transu($fsql->f('fid' . $j));
                            }
                        }
                    }
                }
            }
            $wid            = $msql->f('wid');
            $on[$i]['posi'] = $posi[$msql->f('page')];
            if ($_SESSION['hides'] == 1) {
                $on[$i]['posi'] .= "(" . $msql->f('page') . ")";
            }
            $on[$i]['logintime'] = substr($msql->f('logintime'),-8);
            $on[$i]['savetime']  = substr($msql->f('savetime'),-8);
            $on[$i]['ip']        = $msql->f('ips');
            $on[$i]['addr']      = mb_convert_encoding($ips->getaddress($msql->f('ip')),'utf-8','GBK');
            $on[$i]['server']    = $msql->f('server');
            $on[$i]['os']        = $msql->f('os');
            $on[$i]['uid']       = $msql->f('userid');
            $on[$i]['i']         = $i + 1;
            $i++;
        }
        $msql->query("select username,name,userid from `$tb_user` where layer=1 and ifson=0");
        $i = 0;
        while ($msql->next_record()) {
            $com[$i]['name'] = $msql->f('username') . "(" . $msql->f('name') . ")";
            $com[$i]['id']   = $msql->f('userid');
            $i++;
        }
        $tpl->assign('com', $com);
        $tpl->assign('type', $xtype);
        $tpl->assign('on', $on);
        $tpl->assign('page', page($pcount, $thispage));
        $tpl->display("online.html");
        break;
    case "dellogin":
        if ($_SESSION['admin'] == 1) {
            $layer = transuser($userid, 'layer');
			$id    = explode('|',$_POST['id']);
			$fstr = " ";
			foreach($id as $k => $v){
				if($v=='' | !is_numeric($v)) continue;
				$msql->query("select * from `$tb_online` where id='$v'");
				$msql->next_record();
			    $uid = $msql->f('userid');
			    if($fsql->query("update `$tb_user` set online=0 where userid='$uid' $fstr")){
				   $fsql->query("delete from `$tb_online` where id='$v'");
				}
			}           
        }
		echo 1;
        break;
    case "userzdxx":
include('../func/csfunc.php');
        $uid  = $_POST['uid'];
		$js  = $_POST['js'];
        $zgid = $_POST['zgid'];
        
        $wh = " userid='$uid' ";
        if ($zgid == 99) {
			if($gid==100){
            $wh .= " and gid=100 ";
			$zgid=100;
           } else {
            $wh .= " and gid!=100 ";
			$zgid=1;
           }
		  
		}else if($zgid==100){
			$wh .= " and gid=100 ";
			$zgid=100;
		
		}else{
            $wh .= " and gid!=100 ";
			$zgid=1;
		
		}
        if ($js == 1) {
            $wh .= " and z!=9  ";
        } else if ($js == 0) {
            $wh .= " and z=9  ";
        }

        $time = time() - 86400*7;
        $wh .= " and time>$time  ";

        
        $zcstr = "zc0";
        $sql   = " select count(id) from `$tb_lib` where  $wh ";
        $msql->query($sql);
        $msql->next_record();
         $rcount = pr0($msql->f(0));   
		 $psize = $config['psize1'];  
        $thispage = r1($_REQUEST['PB_page']);
        $page     = new page(array(
            'total' => $rcount,
            'perpage' => $psize,
			'nowindex' => $thispage
        ));
        
		$pstr = $page->show(6);

        $sql = " select * from `$tb_lib` where $wh order by time desc,id desc";
        
        $sql .= " limit " . ($thispage - 1) * $psize . "," . $psize;
        $msql->query($sql);
        $tz  = array();
        $i   = 0;
        $tmp = array();
        while ($msql->next_record()) {

            $tz[$i]['qishu']  = $msql->f('qishu');
            $tz[$i]['je']     = (float) $msql->f('je');
            $tz[$i]['zcje']   = (float) pr2($msql->f('je') * $msql->f($zcstr) / 100);
            $tz[$i]['peilv1'] = (float) $msql->f('peilv1');
            
            $tz[$i]['points'] = (float) $msql->f('points');



            if ($tmp['g' . $msql->f('gid')] == '') {
                $tmp['g' . $msql->f('gid')] = transgame($msql->f('gid'), 'gname');
            }
            if ($tmp['b' . $msql->f('gid') . $msql->f('bid')] == '') {
                $tmp['b' . $msql->f('gid') . $msql->f('bid')] = transb8('name', $msql->f('bid'), $msql->f('gid'));
            }
            if ($tmp['s' . $msql->f('gid') . $msql->f('sid')] == '') {
                $tmp['s' . $msql->f('gid') . $msql->f('sid')] = transs8('name', $msql->f('sid'), $msql->f('gid'));
            }
            if ($tmp['c' . $msql->f('gid') . $msql->f('cid')] == '') {
                $tmp['c' . $msql->f('gid') . $msql->f('cid')] = transc8('name', $msql->f('cid'), $msql->f('gid'));
            }
            if ($tmp['p' . $msql->f('gid') . $msql->f('pid')] == '') {
                $tmp['p' . $msql->f('gid') . $msql->f('pid')] = transp8('name', $msql->f('pid'), $msql->f('gid'));
            }
            $tz[$i]['con']   = $msql->f('content');
            $tz[$i]['wf']    = wf($msql->f('gid'), $tmp['b' . $msql->f('gid') . $msql->f('bid')], $tmp['s' . $msql->f('gid') . $msql->f('sid')], $tmp['c' . $msql->f('gid') . $msql->f('cid')], $tmp['p' . $msql->f('gid') . $msql->f('pid')]);
            $tz[$i]['time']  = $msql->f('time');
            $tz[$i]['z']     = $msql->f('z');
            $tz[$i]['gname'] = $tmp['g' . $msql->f('gid')];
            $tz[$i]['xtime'] = substr($msql->f('time'),-8);
            $tz[$i]['user']  = transu($msql->f('userid'));
            
            $i++;
        }
        $e = array(
            "tz" => $tz,
            "page" => $pstr,
            "js" => $js,
			"zgid" => $zgid,
            "sql" => $sql
        );
        echo json_encode($e);
        unset($e);
        unset($tmp);
        break;

}
?>